/*
 * Copyright (C) 2012 haru Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.harusource.di.delegate.impl;

import java.lang.reflect.Method;
import java.util.Calendar;

import android.view.View;
import android.widget.DatePicker;
import android.widget.DatePicker.OnDateChangedListener;

import com.harusource.di.delegate.Delegate;

/**
 * This class implements DatePicker.OnDateChangedListener.</br>
 * It handles following events of DatePicker.</br>
 * </br>
 * <code>
 * onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth)
 * </code>
 * </br>
 * </br>
 * @see android.widget.DatePicker.OnDateChangedListener#onDateChanged(DatePicker, int, int, int)
 * 
 * @author Hiroki Oizumi
 */
public class DatePickerOnDateChangedListener extends Delegate implements OnDateChangedListener {
    @Override
    public void add(Method template, Object target, Method eventhandle, View view) {
        super.add(template, target, eventhandle, view);
        Calendar calender = Calendar.getInstance();
        ((DatePicker)view).init(calender.get(Calendar.YEAR), calender.get(Calendar.MONTH), calender.get(Calendar.DATE), this);
    }

    @EventHandler
    public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
        Delegate.invoke4(mTarget, mEventHandles, EVENTHANDLE_DEFAULT, view, year, monthOfYear, dayOfMonth);
    }
}
